﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using DocumentManagement.ViewsModels;
using DocumentManagement.Models;
using System.Data;
namespace DocumentManagement.Views
{
    /// <summary>
    /// Interaction logic for ShowItemCreateDocumentUserControl.xaml
    /// </summary>
    public partial class ShowItemCreateDocumentUserControl : UserControl
    {
        ShowItemCreatedocumentViewsModel _showItemCreatedocumentViewsModel;
        public ShowItemCreateDocumentUserControl()
        {
            InitializeComponent();
            _showItemCreatedocumentViewsModel = this.Resources["showItemCreatedocumentViewsModel"] as ShowItemCreatedocumentViewsModel;
        }

        private void addCreateOUTDocMenu_Click(object sender, RoutedEventArgs e)
        {
          
            OptionDocument addWin = new OptionDocument(new CreateSend { CreateSendDate = DateTime.Now }, _showItemCreatedocumentViewsModel.EntityModels);
            addWin.ShowDialog();
            //if (addWin.ShowDocumentOUTRadioButton.IsChecked==true){
            //    CreateDocument addWin1 = new CreateDocument(new CreateSend { CreateSendDate = DateTime.Now }, _showItemCreatedocumentViewsModel.EntityModels);
            //    addWin1.ShowDialog();
            //    addWin1.Unloaded += (s, args) =>
            //    {
            //        _showItemCreatedocumentViewsModel.RefreshData();
            //    };
            //}
            //ShowCreateDataGrid.Items.Refresh();
            //if (addWin1.Closing() 

            //CreateDocumentIN addWin2 = new CreateDocumentIN(new CreateSend { CreateSendDate = DateTime.Now }, _showItemCreatedocumentViewsModel.EntityModels);
            //addWin2.Unloaded += (s, args) =>
            //{
            //    _showItemCreatedocumentViewsModel.RefreshData();
            //};
        }

        private void CreateSendCodeOrTitleTextBox_KeyUp(object sender, KeyEventArgs e)
        {
            _showItemCreatedocumentViewsModel.Filter(CreateSendCodeOrTitleTextBox.Text, FromDatePicker.SelectedDate, ToDatePicker.SelectedDate);
        }

        private void FromDatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            _showItemCreatedocumentViewsModel.Filter(CreateSendCodeOrTitleTextBox.Text, FromDatePicker.SelectedDate, ToDatePicker.SelectedDate);
        }

        private void ToDatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            _showItemCreatedocumentViewsModel.Filter(CreateSendCodeOrTitleTextBox.Text, FromDatePicker.SelectedDate, ToDatePicker.SelectedDate);
        }

        private void editCreateOUTDocMenu_Click(object sender, RoutedEventArgs e)
        {
            if (_showItemCreatedocumentViewsModel.MySelectedEditItemCreateSend.Type == 1)
            {
                CreateDocumentOUT editWin = new CreateDocumentOUT(_showItemCreatedocumentViewsModel.MySelectedEditItemCreateSend, _showItemCreatedocumentViewsModel.EntityModels);
                editWin.ShowDialog();
            }
            if (_showItemCreatedocumentViewsModel.MySelectedEditItemCreateSend.Type == 2)
            {
                CreateDocumentINN editWin = new CreateDocumentINN(_showItemCreatedocumentViewsModel.MySelectedEditItemCreateSend, _showItemCreatedocumentViewsModel.EntityModels);
                
                editWin.PostScriptTextBlock.Visibility = Visibility.Hidden;
                editWin.EndorserTextBlock.Visibility = Visibility.Hidden;
                editWin.PositionTextBlock.Visibility = Visibility.Hidden;
                editWin.stackPanel17.Visibility = Visibility.Hidden;
                editWin.ShowDialog();
            }
          
           
        }

        private void deleteCreateOUTDocMenu_Click(object sender, RoutedEventArgs e)
        {
            _showItemCreatedocumentViewsModel.DeleteFromDatabase();
        }

        private void DG_HyperlinkCreateSend_Click(object sender, RoutedEventArgs e)
        {
            ShowItemFileCreate showFile = new ShowItemFileCreate(_showItemCreatedocumentViewsModel.MySelectedEditItemCreateSend);
            showFile.ShowDialog();
        }

        private void copyCreateOUTDocMenu_Click(object sender, RoutedEventArgs e)
        {
         
        }

        //private void copyCreateOUTDocMenu_Click(object sender, RoutedEventArgs e)
        //{

           

        //    if (_showItemCreatedocumentViewsModel.MySelectedEditItemCreateSend.Type == 1)
        //    {
        //        CreateDocument editWin = new CreateDocument(_showItemCreatedocumentViewsModel.MySelectedEditItemCreateSend, _showItemCreatedocumentViewsModel.EntityModels);
        //        editWin.ShowDialog();
        //    }
        //    if (_showItemCreatedocumentViewsModel.MySelectedEditItemCreateSend.Type == 2)
        //    {
        //        CreateDocumentIN editWin = new CreateDocumentIN(_showItemCreatedocumentViewsModel.MySelectedEditItemCreateSend, _showItemCreatedocumentViewsModel.EntityModels);
        //        editWin.ShowDialog();
        //    }
        //}

   
    }
}
